# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=radare2-keystone
pkgver=920.1cf5851
pkgrel=1
pkgdesc='Keystone assembler plugins for radare2.'
groups=('blackarch' 'blackarch-reversing' 'blackarch-binary'
        'blackarch-disassembler')
arch=('x86_64' 'aarch64')
url='https://github.com/radare/radare2-extras/tree/master/unicorn'
license=('GPL3')
depends=('radare2' 'unicorn' 'keystone' 'yara' 'openssl' 'capstone'
         'linux-headers' 'jansson')
makedepends=('git' 'pkg-config')
source=("$pkgname::git+https://github.com/radare/radare2-extras.git")
install="$pkgname.install"
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd $pkgname

  sed -i 's|~/.config/radare2/plugins|/usr/share/radare2-extras/plugins/keystone|' \
    keystone/Makefile
}

build() {
  cd $pkgname

  cd keystone
  ./configure --prefix=/usr

  make
}

package() {
  cd "$pkgname/keystone"

  install -Dm 755 -t "$pkgdir/usr/share/radare2-extras/plugins/keystone" *.so

  cd ..

  install -Dm 644 -t "$pkgdir/usr/share/doc/radare2-extras/" README.md
  install -Dm 644 COPYING "$pkgdir/usr/share/licenses/radare2-extras/COPYING"
}

